# 方法一 (xpath 匹配文本包含单引号双引号的处理)

def escape_string_for_xpath(s):
    if '"' in s and "'" in s:
        return 'concat(%s)' % ", '\"',".join('"%s"' % x for x in s.split('"'))
    elif '"' in s:
        return "'%s'" % s
    return '"%s"' % s


# 方法二 (xpath 匹配文本包含单引号双引号的处理)
def handle_quotation_value(value):
    new_value = value
    if "'" in value and '"' in value:
        print(''' " ' ''')
        new_value = new_value.replace("'", "\'")
        new_value = 'concat(' + ',\'"\','.join([f'"{part}"' for part in new_value.split('"')]) + ')'


    elif '"' in value:
        print('"')
        new_value = 'concat(' + ',\'"\','.join([f'"{part}"' for part in new_value.split('"')]) + ')'
    elif "'" in value:
        print("'")
        new_value = '"' + new_value.replace("'", "\'") + '"'

    else:
        print('---')
        new_value = '"' + new_value + '"'
        pass
    return new_value
